package com.project.gradeFilter;


import com.project.bean.UserBean;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 用户过滤器
 */
public class CustomerFilter implements Filter {
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        //从session中，取出登录用户信息
        HttpServletRequest request=(HttpServletRequest) servletRequest;
        HttpServletResponse response=(HttpServletResponse) servletResponse;

        UserBean user=(UserBean) request.getSession().getAttribute("loginUser");
        if(user != null ){
            filterChain.doFilter(request,response);
        }else {
            response.sendRedirect("/html/login/login.html");
        }
    }
}
